package com.wei.czz.common.enums.common.exportTask;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-03-19 23:09:40
 * className: TaskTypeEnum 导出/导入任务类型字典枚举类
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum TaskTypeEnum {

    /*
        系统任务类型字典值
        注意：必须保证所有枚举对象前后顺序（即枚举对象的value属性值是升序的）
     */
    COMMENT_LIST_EXPORT(1, "博客评论列表导出"),

    GAME_EXPORT(100, "游戏数据导出"),

    MENU_CHOICE_EXPORT(200, "菜单自选数据导出"),

    DEPT_CHOICE_EXPORT(300, "部门自选数据导出"),
    ;


    /**
     * 字典值
     */
    private final Integer value;

    /**
     * 字典值的描述信息
     */
    private final String name;

    /**
     * 获取枚举对象
     * @param value 值
     * @return 枚举对象
     */
    public static TaskTypeEnum get(Integer value) {
        TaskTypeEnum[] taskTypeEnums = values();

        int left = 0, right = taskTypeEnums.length - 1;
        while (left <= right) {
            int mid = (left + right) >> 1;
            TaskTypeEnum taskTypeEnum = taskTypeEnums[mid];
            if (taskTypeEnum.value > value) {
                right = mid - 1;
            } else if (taskTypeEnum.value < value) {
                left = mid + 1;
            } else {
                return taskTypeEnum;
            }
        }
        return null;
    }

    /**
     * 二分查找任务类型参数值关联的任务描述信息
     * @param value 任务类型
     * @return 任务描述信息
     */
    public static String findName(Integer value) {
        TaskTypeEnum taskTypeEnum = get(value);
        if (Objects.nonNull(taskTypeEnum)) {
            return taskTypeEnum.name();
        }
        return "";
    }

}
